layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func', 'laydate', 'upload'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var laydate = layui.laydate;
    var upload = layui.upload;

    //渲染时间选择框
    laydate.render({
        elem: '#timeLimitls',
        value: new Date().getFullYear(),
        type: 'year',
    });
    var Notice = {
        tableId: "noticeTablels"    //表格id
    };

    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyBxda/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function( index, val ) {
        $("#dmls").append("<option value='"+val.dm+"'>"+val.dm+"</option>");
    } );
    form.render('select');
    /**
     * 导入银行流水Excel
     */
    var loadIndex;
    upload.render({
        elem: '#btnExcel1'
        , url: '/btyYhls/import'
        , accept: "file"
        , exts: 'xls|xlsx|xlsm|xlt|xltx|xltm'
        ,before: function(obj){//参数
            loadIndex = layer.load('正在导入...',2, { shade: [0.15, '#ccc'] });
        }
        , done: function (res) {
            layer.close(loadIndex);
            if (res.state == 0) {
               alert("导入失败！");
            }
            if (res == true) {
                Feng.success("导入成功！");
                table.reload(Notice.tableId);
                $("#btnExcel").unbind("click");
            }
        }
    });
    // 导入excel
    $('#btnExcel').click(function (event) {
        var dm = $("#dmls").val();
        if (dm == ''){
            layer.msg('请选择店名！',{icon: 2, time: 1000})
        } else {
            $('#btnExcel1').click()
        }
    });
    // 搜索按钮点击事件
    $('#btnSearchls').click(function () {
        Notice.search();
    });

    // 导出excel
    $('#btnExpls').click(function () {
        Notice.exportExcel();
    });

    /**
     * 导出excel按钮
     */
    Notice.exportExcel = function () {
        //获取导出Excel的数据
        // var ajax = new $ax(Feng.ctxPath + "/btyYhls/listExportYhls");
        // var dm = $("#dmls").val();
        // var timeLimit = $("#timeLimitls").val();
        // ajax.set("timeLimit", timeLimit);
        // ajax.set("dm", dm);
        // var result = ajax.start();
        // //身份证银行卡导出excel科学计数法问题
        // var lists = result;
        // table.exportFile(tableResult.config.id, lists, 'xls');

        var dm = $("#dmls").val();
        var timeLimit = $("#timeLimitls").val();
        //获取导出Excel的数据
        var url = Feng.ctxPath + "/ckpx/expExcel?dm=" + dm+"&timeLimit="+timeLimit;
        location.href = url;
    };

    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', align: "center", hide: true, sort: true, title: 'id'},
            //{align: 'center', type: "numbers", title: '序号'},
            //{field: 'bh', align: "center", sort: true, title: '编号'},
            {field: 'dm', align: "center", sort: false, title: '店名', width: 200,},
            {field: 'rq', align: "center", sort: false, title: '日期', width: 100},
            {field: 'zc', align: "center", sort: false, title: '支出', width: 90, edit: 'text', totalRow: true},
            {field: 'sr', align: "center", sort: false, title: '收入', width: 120},
            {field: 'ye', align: "center", sort: false, title: '余额', width: 120},
            {field: 'zy', align: "center", sort: false, title: '摘要', edit: 'text', width: 300},
            {field: 'hm', align: "center", sort: false, title: '户名', edit: 'text', width: 100},
            {field: 'sj', align: "center", sort: false, title: '时间', width: 200},
            {field: 'bh', align: "center", sort: false, title: 'ID',width: 100},
            //{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 150}
        ]];
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/btyYhls/list',
        page: true,
        height: "full-120",
        cellMinWidth: 100,
        limit: 20,
        totalRow: true,	//开启合计行
        cols: Notice.initColumn(),
    });


    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['dm'] = $("#dmls").val();
        queryData['timeLimit'] = $("#timeLimitls").val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };



});